<template>
  <div class="form-layout">
    <!--左侧导航-->
    <div class="nav-left">
      <customAnchor
        :itemList="[
          { name: 'box-base', title: '基础信息' },
          { name: 'box-info', title: '手术信息' },
        ]"
      />
    </div>
    <!--表单区域-->
    <div class="form-right" ref="formRight">
      <customForm :data="form" :rules="propRules" ref="editForm" :disabled="propReadonly">
        <template #content>
          <div id="box-base" class="box-title">基础信息</div>
          <customFormItem
            label="患者"
            name="patientName"
            :parent="_self"
            :form="form"
            :readonly="true"
            :showSelectIcon="true"
            @focus="utilSelect.patient(selectChange)"
          />
          <customFormItem
            label="申请医生"
            name="doctorNameApply"
            :parent="_self"
            :form="form"
            :readonly="true"
            :showSelectIcon="true"
            @focus="utilSelect.staff(selectChangeApply)"
          />
          <div id="box-info" class="box-title">手术信息</div>
          <customFormItem label="手术单号" name="code" :parent="_self" :form="form" />
          <customFormItem
            label="手术日期"
            name="date"
            :parent="_self"
            :form="form"
            :type="constCommon.formItemType.datePicker.name"
          />
          <customFormItem label="手术名称" name="name" :parent="_self" :form="form" />
          <customFormItem
            label="主刀医生"
            name="doctorNameSug"
            :parent="_self"
            :form="form"
            :readonly="true"
            :showSelectIcon="true"
            @focus="utilSelect.staff(selectChangeSug)"
          />
          <customFormItem label="主刀医生科室" name="deptName" :parent="_self" :form="form" disabled />
          <customFormItem
            label="手术科室"
            name="deptRoom"
            :parent="_self"
            :form="form"
            :readonly="true"
            :showSelectIcon="true"
            @focus="utilSelect.dept(selectChangeRoom, null, constCommon.dictType.baseDeptTypeOp)"
          />
          <customFormItem
            label="手术间"
            name="deptOp"
            :parent="_self"
            :form="form"
            :readonly="true"
            :showSelectIcon="true"
            @focus="utilSelect.dept(selectChangeOp, constCommon.dictType.baseDeptTypeOp)"
          />
          <customFormItem label="备注" name="remark" :parent="_self" :form="form" />
        </template>
      </customForm>
    </div>
  </div>
</template>

<script>
import customAnchor from '@/components/custom/form/customAnchor.vue'

export default {
  data() {
    return {
      form: {},
      viewData: {},
    }
  },
  methods: {
    //患者选择后
    selectChange(row, refName) {
      this.$set(this.form, 'patientId', row.id)
      this.$set(this.form, 'patientNo', row.no)
      this.$set(this.form, 'patientName', row.name)
    },
    //选择申请医生
    selectChangeApply(row) {
      this.$set(this.form, 'staffCodeApply', row.code)
      this.$set(this.form, 'doctorNameApply', row.name)
    },
    //选择主刀医生
    selectChangeSug(row) {
      this.$set(this.form, 'staffCodeSug', row.code)
      this.$set(this.form, 'doctorNameSug', row.name)
      this.$set(this.form, 'deptId', row.officeId)
      this.$set(this.form, 'deptName', row.deptName)
    },
    //选择手术科室
    selectChangeRoom(row) {
      this.$set(this.form, 'deptIdRoom', row.id)
      this.$set(this.form, 'deptRoom', row.name)
    },
    //选择手术间
    selectChangeOp(row) {
      this.$set(this.form, 'deptIdOp', row.id)
      this.$set(this.form, 'deptOp', row.name)
    },
  },
  created() {
    this.$emit('event-register', {
      validate: (callback) => {
        return this.$refs.editForm.validate(callback)
      },
      beforeSave: () => {
        this.$emit('data-callback', this.form)
        return true
      },
      afterMove: (formData) => {
        this.form = global.utils.jsonClone(formData)
      },
      afterSave: () => {},
      beforeDelete: () => {
        return true
      },
      afterDelete: () => {},
      beforeFlow: () => {
        return true
      },
      afterFlow: () => {},
      beforeClose: () => {
        return true
      },
    })
  },
  props: {
    propParent: Object,
    propInitData: Object,
    propPrimaryKey: String,
    propDictionaries: Object,
    propCurrentRow: Object,
    propViewFormData: Object,
    propReadonly: Boolean,
    propStatus: String,
    propRules: Object,
  },
  components: {
    customAnchor,
  },
  computed: {},
}
</script>
